package fr.ups.jim.rdf.tp4;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

public class Vector {

	private List<Double> values;

	public Vector(List<Double> values) {
		this.values = values;
	}

	public Vector(String values) {
		this.values = new ArrayList<Double>();
		for (String v : values.split(" ")) {
			this.values.add(Double.parseDouble(v));
		}
	}

	public Vector(int n) {
		this.values = new ArrayList<Double>();
		
		for (int i = 0; i < n ; i++) {
			Double t = new Double(0.0);
			this.values.add(t);
		}
	}

	public Vector add(Vector v) {
		ArrayList<Double> res = new ArrayList<Double>();
		for (int i = 0; i < this.values.size(); i++) {
			res.add(this.values.get(i) + v.values.get(i));
		}

		return new Vector(res);
	}

	public double dot(Vector v) {
		double res = 0.0;
		for (int i = 0; i < this.values.size(); i++) {
			res += this.values.get(i) * v.values.get(i);
		}
		return res;
	}

	public Vector add(double lambda) {
		ArrayList<Double> res = new ArrayList<Double>();
		for (int i = 0; i < this.values.size(); i++) {
			res.add(this.values.get(i) * lambda);
		}

		return new Vector(res);
	}

	@Override
	public String toString() {
		String res = "";
		for (Double v : this.values) {
			res += " " + v;
		}
		return res.substring(1);
	}

	public static void main(String[] s) {
		Vector v1 = new Vector("1 2 3 4 5");
		Vector v2 = new Vector("6 7 8 9 10");

		System.out.println(v1);
		System.out.println(v1.add(v2));
		System.out.println(v1.dot(v1));
		System.out.println(v1.add(2.0));
	}

}
